package com.his.his_system.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.his.his_system.common.util.ResultAdvice;
import com.his.his_system.common.vo.PageHelp;
import com.his.his_system.domain.DzmHisDoctor;
import com.his.his_system.domain.DzmHisMember;
import com.his.his_system.service.DzmHisDoctorService;
import com.his.his_system.vo.DoctorVo;
import com.his.his_system.vo.MemberAndDoctorVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.*;

import javax.print.Doc;
import java.lang.reflect.Member;
import java.util.HashMap;
import java.util.List;

@RequestMapping("/his/sys/doctor/")
@RestController
@ResponseBody
public class DoctorController {

    @Autowired
    private DzmHisDoctorService doctorService;

    @GetMapping("list")
    public ResultAdvice list(PageHelp param) {
        PageHelper.startPage(param.getCurrentPage(), param.getPageSize());
        List<DoctorVo> hisDoctors = doctorService.selectAll();
        return ResultAdvice.success(new PageInfo<>(hisDoctors), "查询全部");
    }

    @GetMapping("like")
    public ResultAdvice like(PageHelp param) {
        PageHelper.startPage(param.getCurrentPage(), param.getPageSize());
        List<DoctorVo> hisDoctors = doctorService.selectLike(param.getKeyWord());
        QueryWrapper<Object> qr = new QueryWrapper<>();

        return ResultAdvice.success(new PageInfo<>(hisDoctors), "模糊查询");
    }

    @PostMapping("add")
    public ResultAdvice add(@RequestBody MemberAndDoctorVo param) {
        Boolean flag = doctorService.add(param);
        return ResultAdvice.success(flag,"添加成功");
    }
//    根据ID查询
    @GetMapping("{id}")
    public ResultAdvice getById(@PathVariable("id") Integer id) {
        MemberAndDoctorVo dvo =  doctorService.selById(id);
        return ResultAdvice.success(dvo);
    }

    @PostMapping("modify")
    public ResultAdvice moidify(@RequestBody MemberAndDoctorVo param) {
        Integer affect =  doctorService.modify(param);
        return ResultAdvice.success(affect);
    }


    @PostMapping("reset/{id}")
    public ResultAdvice reset(@PathVariable("id") Integer id) {
        return  ResultAdvice.success(doctorService.reset(id));
    }

}
